package com.iss.ssm0531.dao;

import com.iss.ssm0531.dao.provider.UserProvider;
import com.iss.ssm0531.model.QueryBean;
import com.iss.ssm0531.model.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface UserDAO {


    @Select("select * from user")
  /*  @Results( value = {
            @Result(column = "user_id" ,property = "password"),
            @Result(column = "role_id",property ="role",
                    one = @One(select = "com.iss.ssm0531.dao.RoleDAO.selectByPrimaryKey"))
    }

    )*/
    public List<User> selectAll();

    @Select("select * from user where role_id=#{roleId}")
    public List<User> selectByRoleId(Integer roleId);

    @Select("select * from user where user_id=#{userId}")
    public User selectByPrimary(@Param("userId") Integer userId);

    @Select("select * from user where username=#{username} and password=#{password}")
    public User selectByExample(User user);

    @Select("select * from user where username=#{username} and password=#{password}")
    public User selectByMap(Map map);

    @Select("<script> select * from user <where> " +
            "<if test=\"username!=null\"> username=#{username} </if>" +
            " <if test=\"password!=null\"> and password=#{password} </if> " +
            "</where> </script>")
    public List<User> selectByMutiple(User user);


    @UpdateProvider(type = UserProvider.class,method = "updateSQL2")
    /*@Update("<script></script>");*/
    int updateUser(User user);

}